package com.example.demo.mp4Test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class GreenScreenVideoConverter {

    public static void main(String[] args) {
        // 您需要提前安装FFmpeg，并将其添加到系统路径中
        String ffmpegPath = "ffmpeg";

        // 输入视频文件路径和输出视频文件路径
        String inputFile = "D:\\Code\\AAAAAA_MyUtil\\src\\main\\java\\com\\example\\demo\\mp4Test\\file\\f92b2ee691e990f0ee4a0f06dd3d68c8.mp4";
        String outputFile = "D:\\Code\\AAAAAA_MyUtil\\src\\main\\java\\com\\example\\demo\\mp4Test\\newFile\\output_video.mov";

        // 定义FFmpeg命令
        List<String> command = new ArrayList<>();
        command.add(ffmpegPath);
        command.add("-i");
        command.add(inputFile);
        command.add("-filter_complex");
        command.add("[0:v]chromakey=0x00FF00:0.1:0.2[ckout];[ckout]split[m][a];[a]geq='if(lt(alpha(X,Y),16),255,alpha(X,Y))'[alf];[m]scale=hd720[fg];[alf][fg]alphamerge");
        command.add("-c:v");
        command.add("qtrle");
        command.add(outputFile);

        // 执行FFmpeg命令
        try {
            ProcessBuilder builder = new ProcessBuilder(command);
            builder.redirectErrorStream(true);
            Process process = builder.start();
            int exitCode = process.waitFor();
            System.out.println("FFmpeg exited with code " + exitCode);
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}
